package com.lyyzoo.gpss.web.base;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lyyzoo.bean.Result;
import com.lyyzoo.data.domain.Page;
import com.lyyzoo.gpss.entity.base.Employee;
import com.lyyzoo.gpss.service.base.EmployeeService;
import com.lyyzoo.gpss.web.BaseController;

/**
 * <p>
 *
 * @author xmpu
 * @date 2017-04-05
 */
@Controller
@RequestMapping("/admin/employee")
@Api(value = "/admin/employee", tags = "员工管理")
public class EmployeeController extends BaseController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = {"", "/"})
    @ApiOperation(value = "", notes = "", httpMethod = "GET", response = String.class)
    public String index(){
        return "/base/employee";
    }

    @RequestMapping("/page")
    @ApiOperation(value = "", notes = "", httpMethod = "GET", response = Page.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="name", value="名称", dataType="String", paramType = "query"),
            @ApiImplicitParam(name="type", value="类型", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name="pageNumber", value="页号", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name="pageSize", value="显示条数", required = true, dataType = "Integer", paramType = "query")
    })
    public Page<Employee> page(@RequestParam() String name,
                               @RequestParam() String type,
                               @RequestParam() int pageNumber,
                               @RequestParam() int pageSize){

        return employeeService.page(name, type, pageNumber, pageSize);
    }

    /**
     * 保存或修改
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "保存或修改", notes = "", httpMethod = "POST", response = Result.class)
    public Result save(Employee employee){
        return employeeService.save(employee, getCurrentUser());
    }

    @RequestMapping("/remove")
    @ResponseBody
    @ApiOperation(value = "删除", notes = "", httpMethod = "GET", response = Result.class)
    public Result remove(Long id){
        return employeeService.remove(id, getCurrentUser());
    }

}
